package question

import (
	"github.com/gogf/gfer/app/model/question"
)

const (
	PageSize = 30
)

// 查询问答列表
func GetList(page, sort int) []*question.Entity {
	model := question.Model.Page(page, PageSize).FieldsEx("content")
	switch sort {
	case 1:
	case 2:
	default:
		// 默认排序，按照发布顺序
		model = model.Order("id", "desc")
	}
	list, err := model.All()
	if err != nil {
		panic(err)
	}
	return list
}

// 查询用户的问答列表
func GetListByUid(uid, page int) []*question.Entity {
	list, err := question.Model.
		Page(page, PageSize).
		Where("uid", uid).
		FieldsEx("content").
		Order("id", "desc").
		All()
	if err != nil {
		panic(err)
	}
	return list
}

// 查询指定的文档详情
func GetDetail(id int) *question.Entity {
	one, err := question.Model.FindOne(id)
	if err != nil {
		panic(err)
	}
	return one
}
